package com.gz.logistics.library.listener;

import com.gz.logistics.library.pojo.ClothesBug;
import com.gz.logistics.library.pojo.ClothesColor;
import com.gz.logistics.library.util.Constants;
import com.gz.logistics.library.util.CrashHandler;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * 杜志娟
 * 查询小区的监听
 * Created by Administrator on 2016/3/11.
 */
public abstract class GetClothesBugListener extends BaseListener {
    private String TAG = GetClothesBugListener.class.getSimpleName();
    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        try {
            int status = response.getInt(Constants.REQ_REF);
            String msg = response.getString(Constants.REQ_MSG);
            switch(status){
                case Constants.REQ_OK:
                    JSONArray jsonArray = response.getJSONArray(Constants.REQ_RESULT);
                    onResponseSuccess(ClothesBug.parse(jsonArray));
                    break;
                case Constants.REQ_PARTS_IS_EMPTY:
                    onNoMoreData();
                    break;
            }

        } catch (JSONException e) {
            onFailure(statusCode, headers, e, new JSONObject());
        }
    }


    @Override
    public void onNoMoreData() {

    }

    @Override
    public void onNoNetWork() {

    }

    @Override
    public void onOffline() {

    }

    @Override
    public void onResponseFailed() {

    }
    @Override
    public void onFailure(int statusCode,
                          Header[] headers,
                          Throwable throwable,
                          JSONObject errorResponse) {
        CrashHandler.e(throwable);
        onResponseFailed();
    }
    public abstract void onResponseSuccess(List<ClothesBug> bugs);
}
